package com.hzdl.cinema.web.servlet;


import com.hzdl.cinema.Service.PlayViewService;
import com.hzdl.cinema.Service.impl.PlayViewServiceImpl;
import com.hzdl.cinema.dao.PlayViewDao;
import com.hzdl.cinema.dao.impl.PlayViewDaoImpl;
import com.hzdl.cinema.domain.PageBean;
import com.hzdl.cinema.domain.Play;
import com.hzdl.cinema.domain.User;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/play/*")
public class PlayView extends BaseServlet {
    PlayViewService playViewService = new PlayViewServiceImpl();

    //首页展示
    public void findMovie(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //分页 当前页，每页条数
        String currentPage = request.getParameter("currentPage");
        String rows = request.getParameter("rows");
        //未分页前的查询
        //List<Play> list = playViewService.findMovie();
        PageBean<Play> playPageBean = playViewService.findMovie(Integer.parseInt(currentPage), Integer.parseInt(rows));
        User userLogin = (User) request.getSession().getAttribute("userLogin");

        writeValue(response, playPageBean);

    }

    //搜索影片
    public void searchMovie(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String searchOne = request.getParameter("searchOne");
        //分页 当前页，每页条数
        String currentPage = request.getParameter("currentPage");
        String rows = request.getParameter("rows");
        //分页之前的查询
//        List<Play> play = playViewService.searchMovie(searchOne);
        PageBean<Play> playPageBean = playViewService.searchMovie(searchOne, Integer.parseInt(currentPage), Integer.parseInt(rows));

        writeValue(response, playPageBean);
    }

    //查找热门
    public void findHot(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Play> list = playViewService.findHot();
        writeValue(response, list);


    }

    //影片详情
    public void filmDetails(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String playName = request.getParameter("playName");
        Play play = playViewService.filmDetails(playName);
        writeValue(response, play);
    }

    public void userLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
        User userLogin =(User) request.getSession().getAttribute("userLogin");
        writeValue(response,userLogin);
    }
	
	
	  public void findAllPlay(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Play> allPlay= playViewService.findAllPlay();
        writeValue(response,allPlay);
    }
}

